<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑楼座单元</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        var buildingId = new Ext.form.Hidden({
          name: 'id'
        });

        var buildingUnitNumber = new Ext.form.TextField({
          fieldLabel: '楼座单元编号',
          allowBlank: false,
          name: 'number',
          anchor: '90%'
        });

        var buildingUnitName = new Ext.form.TextField({
          fieldLabel: '楼座单元名称',
          allowBlank: false,
          name: 'name',
          anchor: '90%'
        });

        //付款方式
        var buildingType = new Ext.form.RadioGroup({
          //width : 220,
          fieldLabel: '建筑类型',
          name:'sub_type',
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          columns : 2,
          anchor: '100%',
          vertical :false,
          items:[
            {boxLabel:'多层',inputValue:'多层',name:'sub_type',checked:true},
            {boxLabel:'高层',inputValue:'高层',name:'sub_type'}
          ]
        });
        
        //提交按钮
        var editBuildingUnitButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            editBuildingUnitButton.setDisabled(true);
            if (editBuildingUnitFormPanel.form.isValid()) {
              editBuildingUnitFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    editBuildingUnitWin.destroy();
                    buildingUnitDS.reload();
                  } else {
                    Ext.MessageBox.alert('消息', resp.result.info);
                    editBuildingUnitButton.enable();
                  }
                },
                failure: function(result, request){
                  editBuildingUnitButton.enable();
                  Ext.MessageBox.alert('消息', '服务器的通信失败!');
                }
              });
            }
            else {
              editBuildingUnitButton.enable();
              //Ext.MessageBox.alert('输入验证有错', '请输入必输选项');
            }
          }
        })
        
        var editBuildingUnitFormPanel = new Ext.form.FormPanel({
          labelWidth: 80,
          width: '270',
          labelAlign: 'right',
          frame : true,
          url: '/building/updateBuildingUnit',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'number'
            }, {
              name: 'name'
            }, {
              name: 'sub_type'
            }]),
          items: [buildingUnitNumber,buildingUnitName,buildingType,buildingId],
          buttons: [editBuildingUnitButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                editBuildingUnitWin.destroy();
              }
            }]
        });
        editBuildingUnitFormPanel.render('edit_buildingUnit_form');
        //导入数据
        editBuildingUnitFormPanel.form.load({
          url: '/building/getBuildingUnitById?building_id=<%=@buildingId%>',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
      })
    </script>
    <div id="edit_buildingUnit_form"></div>
  </body>
</html>
